
<table border="1" width="100%">

    <tr>
        <td><h1> Who online</h1>
            <div id="div_online">

                <?php
                    $out = file_get_contents(sfConfig::get('app_site_url').'/cgi/online.php');
                    echo $out;
                ?>


            </div>
            		<?php if ($sf_user->isAuthenticated()): ?>
			<?php echo jq_periodically_call_remote(array(
					'frequency' => 20,
                                        'update' => 'div_online',
                                        'script'=>true,
                                        'method'=>'GET',
					'url' => sfConfig::get('app_site_url').'/cgi/online.php',
			)) ?>
                        <?php endif ?>
        </td>
         <td>
            flesh
        </td>
    </tr>
    <tr>
        <td>
            <?php if($active_room):?>
             <h1> Active room  <?= __('chat width ').$active_room->getsfGuardUserRelatedByToId() ?></h1>
             <?php if ($sf_user->isAuthenticated()): ?>
             <?php echo jq_periodically_call_remote(array(
					'frequency' => 10,
                                        'update' => 'div_message',
                                        'script'=>true,
                                        'method'=>'GET',
					'url' => sfConfig::get('app_site_url').'/cgi/send.php?to_id='.$active_room->getToId().'&from_id='.$active_room->getFromId(),
			)) ?>
                        <?php endif ?>

             <div id="div_message" style="border: 1px solid black; width: 600px; height: 300px; overflow: auto">

               <?php
                    $out = file_get_contents( sfConfig::get('app_site_url').'/cgi/send.php?to_id='.$active_room->getToId().'&from_id='.$active_room->getFromId());
                    echo $out;
                ?>

             </div>

            
               

                 <?php echo jq_form_remote_tag(array(
                 'url'      =>  sfConfig::get('app_site_url').'/cgi/send.php',
                 'update'   => 'div_message',
                 'loading'  => "$('#indicator').show();",
                 'complete' => "$('#indicator').hide();scroll();clear()",
               ),array('class'=>'form_style')) ?>

            
             <textarea name ="content" id="content" style="width: 400px; height: 100px"> </textarea>
           
             <input type="hidden" name="to_id" value="<?php echo $active_room->getToId() ?>">
             <input type="hidden" name="from_id" value="<?php echo $active_room->getFromId() ?>">
           
             <div id="indicator" style="position: absolute; height:25px;   text-align: center; background: red; display: none; width: 100px">
            <span style="color: white"><?php echo __('подождите...')?></span>
             </div>
            
           <br />
         

          <input class="but_style" type="submit" value="<?= __('Send message')?>" />

</form>
  
             <?php else: ?>
                <?=__('No active room')?>
             <?php endif; ?>
        </td>
         <td>
           <h1> My abonents</h1>
           <div id="div_abonent">

                <?php
                    $out = file_get_contents( sfConfig::get('app_site_url').'/cgi/abonent.php?id='.sfContext::getInstance()->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
                    echo $out;
                ?>

           </div>
                       		<?php if ($sf_user->isAuthenticated()): ?>
				                  <?php echo jq_periodically_call_remote(array(
					'frequency' => 20,
                                        'update' => 'div_abonent',
                                        'script'=>true,
                                        'method'=>'GET',
					'url' => sfConfig::get('app_site_url').'/cgi/abonent.php?id='.sfContext::getInstance()->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ),
			)) ?>
                        <?php endif ?>
        </td>
    </tr>

</table>

<script>
    function scroll(){
    var scr = document.getElementById('div_message');
    var sd = (scr.scrollHeight - scr.scrollTop <= scr.offsetHeight);
    scr.scrollTop = scr.scrollHeight;
    document.getElementById('content').text = '';
    
    }
    </script>
